/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.business.repository;

import me.zhengjie.business.domain.Fpry;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
* @website https://el-admin.vip
* @author xiahongbo
* @date 2022-06-16
**/
public interface FpryRepository extends JpaRepository<Fpry, String>, JpaSpecificationExecutor<Fpry> {


    @Modifying
    @Query(value = "UPDATE BIS_FPRY SET BIS_FPRY_ZT='1' WHERE BIS_FPRY_ZHSQ_ID=?1 AND BIS_FPRY_ZT = '0'",nativeQuery = true)
    void updateFpryZt(Long zhid);

    @Modifying
    @Query(value = "UPDATE BIS_FPRY SET BIS_FPRY_ZT='1',BIS_FPRY_WCSJ=SYSDATE WHERE BIS_FPRY_ZHSQ_ID=?1 AND BIS_FPRY_ZT = '0' AND BIS_FPRY_RYLX=?2",nativeQuery = true)
    void updateFpryWczt(Long zhid, String rylx);


    @Modifying
    @Query(value = "update BIS_FPRY set BIS_FPRY_ZT = '0' where BIS_FPRY_ID in " +
            "(select * from (select t.bis_fpry_id from BIS_FPRY t where t.bis_fpry_zhsq_id=?1 order by t.bis_fpry_fpsj desc) where rownum=1)",nativeQuery = true)
    void updateResumeFpryZt(Long zhid);
}